import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'

// 自动导入vue中hook reactive ref等
import AutoImport from 'unplugin-auto-import/vite'
//自动导入ui-组件 比如说ant-design-vue  element-plus等
import Components from 'unplugin-vue-components/vite'
//ant-design-vue
import { AntDesignVueResolver,  } from 'unplugin-vue-components/resolvers'
import VueDevTools from 'vite-plugin-vue-devtools'

import path from "path";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";

// https://vitejs.dev/config/   
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    AutoImport({
      imports: 'vue',
      //ant-design-vue
      resolvers: [AntDesignVueResolver(), ]
    }),

    VueDevTools(),

    Components({
      //ant-design-vue
      resolvers: [AntDesignVueResolver()]
    }),
    createSvgIconsPlugin({
      iconDirs: [path.resolve(process.cwd(), "./src/icons/svg")],
      // 指定symbolId格式
      symbolId: "icon-[name]",
      customDomId: "turing-planet-svgs", // 避免多项目互相影响
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },


  server: {
    //使用IP能访问
    host: '0.0.0.0',
    // 热更新
    hmr: true,
    //设为 true 时若端口已被占用则会直接退出，而不是尝试下一个可用端口
    strictPort: false,
    cors: true,
    open: true,
    proxy: {
      '/ai': {
        target: 'https://searchalgtest.zuiyouliao.com',
        changeOrigin: true, //用于控制请求头中的host值
        rewrite: (path) => {
          return path.replace(/^\/ai/, '')
        }
      },
      '/api': {
        //'/api'是自行设置的请求前缀
        target: 'https://hqformutest.zuiyouliao.com',
        changeOrigin: true, //用于控制请求头中的host值
        rewrite: (path) => {
          console.log('rewrite path',path)
          return path
        }
      }
      
      
    }
  },
  esbuild: {
    drop: ['console', 'debugger'],
  }
})
